//引入axios
import axios from "axios";
//引入进度条
import nprogress from "nprogress";
import 'nprogress/nprogress.css'
//引入用户身份唯一标识插件UUID
// import {a as haha} from '@/utils/userId'; //分别暴露起别名
// import {default as GetUserTempId } from '@/utils/userId';//默认暴露起别名
import GetUserTempId from '@/utils/userId';
import store from "@/store";
//加载隐藏小球
nprogress.configure({ showSpinner: false })

//axios.create方法执行:返回也是axios
const request = axios.create({
    baseURL: '/dev-api',//请求基础路径
    timeout: 5000//超时的时间
});

//请求拦截器:只要发请求(发请求之前触发) config:配置对象
request.interceptors.request.use((config) => {
    nprogress.start();
    //axios请求头携带公共参数---用户未登录的身份标识
    config.headers.userTempId = GetUserTempId();
    //先判断用户是否有token
    // if(store.state.user.token){
    //     config.headers.token = store.state.user.token;
    // }
    return config
});

//响应拦截器
// request.interceptors.response.use((res) => {
//     nprogress.done();
//     return res.data;
// }, (error) => {
//     const status = error.request.status;
//     switch (status) {
//         case 404:
//             alert('请求失败');
//             break;
//         case 403:
//             alert('未授权');
//             break;
//         case 500 || 501 || 502 || 503 || 504:
//             alert('服务器BBQ');
//             break;
//     }
//     return new Promise((resolve, reject) => { })
// })
export default request;